package cn.itcast.hotel.controller;

import cn.itcast.hotel.pojo.PageResult;
import cn.itcast.hotel.pojo.RequestParams;
import cn.itcast.hotel.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hotel")
public class HotelController {
    @Autowired
    private HotelService hotelService;

    /**
     * 分页查询
     * @param params 请求参数对象，包含用户输入的关键字
     * @return 酒店文档列表
     */
    @PostMapping("/list")
    public PageResult search(@RequestBody RequestParams params){
            return hotelService.search(params);
        }

    /**
     * 通过条件过滤查询进行桶的聚合--bocket
     * @param params
     * @return
     */
    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params){
        return hotelService.getFilters(params);
    }

    /**
     * 实现搜索框自动补全
     * @param prefix
     * @return
     */
    @GetMapping("suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix) {
        return hotelService.getSuggestions(prefix);
    }
}
